package com.edu.gcu.manager.service.impl;

import com.edu.gcu.manager.service.IDealerService;
import com.edu.gcu.system.common.Const;
import com.edu.gcu.system.common.ServerResponse;
import com.edu.gcu.system.dao.UserMapper;
import com.edu.gcu.system.pojo.User;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.google.common.base.Splitter;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author polo
 * @version V1.0
 * @description: 经销商service接口实现类
 * @date 2018-02-20-12:22
 */

@Service("iDealerService")
public class IDealerServiceImpl implements IDealerService {

    @Autowired
    private UserMapper userMapper;

    /*
     * 用户列表
     * */
    @Override
    public ServerResponse userList(String nickname, String orderBy, Integer pageNum, Integer pageSize) {
        // 分页排序
        PageHelper.startPage(pageNum, pageSize);
        if (StringUtils.isNotBlank(orderBy)) {
            if (Const.UserOrderBy.LOGIN_TIME_DESC_ASC.contains(orderBy)) {
                List<String> orderBys = Splitter.on("-").splitToList(orderBy);
                PageHelper.orderBy(orderBys.get(0) + " " + orderBys.get(1));
            }
        }
        List<User> userList = userMapper.selectList(nickname);
        PageInfo pageInfo = new PageInfo(userList);
        return ServerResponse.createBySuccess(pageInfo);
    }
}
